import React, { useMemo } from "react";
import "./index.css";
import { transformTime } from "../../utils";
import dayjs from "dayjs";

export default ({ time, onClick }) => {
  const date = transformTime(time);
  const isToday = date === transformTime();

  const dateString = useMemo(() => dayjs(date).format("YYYY-MM-DD"), [date]);

  const weekString =
    "周" +
    ["日", "一", "二", "三", "四", "五", "六"][new Date(date).getDay()] +
    (isToday ? "今天" : "");

  return (
    <div className="depart-date" onClick={onClick}>
      <input type="hidden" name="date" value={dateString} />
      {dateString} <span className="depart-week">{weekString}</span>
    </div>
  );
};
